home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4555 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.0 KB

  1. Path: guitar.hal.com!not-for-mail
  2. From: blair@hal.COM (Blair Martin)
  3. Newsgroups: comp.lang.c++
  4. Subject: Interpreting whitespace w. cin
  5. Date: 30 Jan 1996 15:56:41 -0800
  6. Organization: HaL Computer Systems, Inc.
  7. Message-ID: <4emb7p$u0@guitar.hal.com>
  8. NNTP-Posting-Host: guitar.hal.com
  9.  
  10. I want to write a program that uses new and delete to dynamically
  11. allocate exactly enough free memory to hold string input data.
  12.  
  13. That is, instead of allocating a fixed array of
  14. characters from the stack, receive one character at a time and
  15. continually allocate, copy, and release space so that the physical
  16. and logical lengths of the buffer area are always the same.
  17. When the newline character is encountered, print the string
  18. and release the space. Then prompt for the next string. When
  19. EOF is entered, terminate the program.
  20.  
  21.  
  22. The problem is with a loop like
  23.  
  24.     while (!(cin >> input).eof())
  25.     {
  26.             ...
  27.     }
  28.  
  29. there is no way to know when a newline is encountered since
  30. all whitespace is ignored.
  31.  
  32. Is there another way to do this?
  33.  
  34.  
  35. blair
  36.